<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class DefaultController extends Controller
{
    public function indexAction(Request $request)
    {

        # render login page
        $em = $this->getDoctrine()->getManager();
 
        $qb = $em->getRepository('AppBundle:Pages')->createQueryBuilder('p');
    
        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate($qb, $request->query->getInt('page', 1),9);
        return $this->render('/index/list.html.twig', [
            'pagination' => $pagination,
        ]);
    }

    /**
     * show page
     *
     */
    public function showPageAction(Request $request)
    {
        $id = intval($request->get('id'));
        $em = $this->getDoctrine()->getManager();
        $page =  $em->getRepository('AppBundle:Pages')->findOneById($id);
        $isMobile = isMobile();

        if($page&&!$page->getMContent()){
            $isMobile=false;
        }

        return $this->render('index/show.html.twig',array('page'=>$page,'isMobile'=>$isMobile));
    }
}

    